package com.ljy.utyun.swagger;

import com.ljy.utyun.sql.SqlFieldCollector;

import java.io.*;
import java.util.Map;
import java.util.Set;

/**
 * @author lijunying
 * @date 2020/10/15 15:25
 */
public class SwaggerHelper {

    public static void main(String[] args) throws IOException {
        long start=System.currentTimeMillis();
//        F:\project\git\businessCloud_apollo_swagger
        SwaggerHelper helper=new SwaggerHelper();
//        String path="F:\\project\\git\\businessCloud_manyStores_swagger\\goods-service\\src\\main\\java\\cn\\com\\ut\\biz";
        String path="F:\\project\\git\\businessCloud_manyStores_swagger\\aftersale-service\\src\\main\\java\\cn\\com\\ut\\biz";
        helper.process(path);
        System.out.println("已结束，耗时："+(System.currentTimeMillis()-start)+"ms");
    }

    /**
     * 1.寻找java文件
     * 2.判断是否是规定的java文件
     * 3.修改java文件
     * 4.替换java
     * @param path
     * @throws IOException
     */
    public void process(String path) throws IOException {
        //获取字段描述信息
        String sqlPath="C:\\Users\\lijunying.UT\\Desktop\\business_sql";
        SqlFieldCollector sqlFieldCollector=new SqlFieldCollector(sqlPath);
        Map<String,Set<String>> fieldCommentMap=sqlFieldCollector.scanAndGetComment();

        SwaggerProcessor controllerSwaggerProcessor=new ControllerSwaggerProcessor();
        SwaggerProcessor pojoSwaggerProcessor=new PojoSwaggerProcessor(fieldCommentMap);
        File file=new File(path);
        if(file.isDirectory()){
            for(String next:file.list()){
                process(path+"\\"+next);
            }
        }else{
            controllerSwaggerProcessor.process(file);
            pojoSwaggerProcessor.process(file);
        }
    }

}
